﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication18
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }
        Boolean Flag=true;
        char r = 'R';//just to intlizing
        private void PLay2_Click(object sender, EventArgs e)
        {
            if(Flag==true)
            {
            var Fname=FirstName.Text.ToLower();
            var Sname = SecondName.Text.ToLower();
            Sname = Sname.Trim();
            String[] name1_split = Fname.Split(new Char[] { ' ' });
            String[] name2_split = Sname.Split(new Char[] { ' ' });
                if (Fname == "" || Sname =="")
                {
                   MessageBox.Show("Enter a valid name Pulka ga");
                }
                else if (Fname == Sname)
                {
                    MessageBox.Show("Relation Should Exist between two persons, Not between You and You stupid I know you love your self");
                }
                else if (!((Fname == "" || Sname == "") && (Fname == Sname)))
                {
                    Fname = "";
                    Sname = "";
                    for (int i = 0; i < name1_split.Length; i++)
                    {
                        Fname = Fname + name1_split[i];
                    }
                    for (int i = 0; i < name2_split.Length; i++)
                    {
                        Sname = Sname + name2_split[i];
                    }

                    int a = Fname.Length, b = Sname.Length;
                    for (int i = 0; i < a; i++)
                    {
                        char[] fn = Fname.ToCharArray();
                        char h = fn[i];
                        for (int j = 0; j < b; j++)
                        {
                            char[] sn = Sname.ToCharArray();
                            char d = sn[j];
                            if (h == d)
                            {
                                Fname = Fname.Remove(i, 1);
                                Sname = Sname.Remove(j, 1);
                                a = Fname.Length;
                                b = Sname.Length;
                                i = 0;
                                j = 0;
                            }
                        }
                    }

                    int count = Fname.Length + Sname.Length;

                    String temp1;
                    temp1 = "FLAMES";

                    String newStr;
                    int c = 6;//length of flames intial later it will decreement by one in loop
                    if (count < 6 && count > 0)
                    {
                        for (int i = 0; c >= count; i++)
                        {
                            if (c == count)
                            {
                                temp1.Remove(count - 1, 1);
                                c--;
                            }
                            else
                            {
                                temp1.Remove(count - 1, 1);
                                int l = temp1.Length - count;
                                newStr = temp1.Substring(count - 1, l + 1);
                                newStr = newStr + temp1.Substring(0, count - 1);
                                temp1 = newStr;
                                c--;
                            }

                        }
                    }
                    if (count > 0)
                    {
                        for (int k = 1; c > 0; k++)
                        {
                            if ((k + c) % count == 0)
                            {
                                if (temp1.Length > 1)
                                {
                                    if (k % c == 0)
                                    {

                                        temp1.Remove(temp1.Length - 1, 1);
                                    }
                                    else
                                    {
                                        temp1 = temp1.Remove((k % c) - 1, 1);
                                    }
                                    if ((k % c) != 0)//added this condtion to avoid deleting of first leter when the directly the last character is deleted from the string..SO we need to start from the first..
                                    {
                                        int l = temp1.Length - (k % c);
                                        newStr = temp1.Substring((k % c) - 1, l + 1);
                                        newStr = newStr + temp1.Substring(0, (k % c) - 1);
                                        temp1 = newStr;
                                    }
                                }
                                c--;//decrementing the size of flames strings intailally 6 after deletintg every element it is decremented by 1
                            }
                        }
                        Char[] temp = temp1.ToCharArray();
                        r = temp[0];// the result is stored at this location
                    }

                    if (r == 'F')
                    {
                        MessageBox.Show("Friends, Jagratha ra ", "Result", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        this.BackColor = Color.Aqua;
                    }
                    else if (r == 'L' && Flag == true)
                    {
                        MessageBox.Show("Lovers Pandaga Chesuko, naku kuda chudu mama", "Result", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        this.BackColor = Color.HotPink;
                    }
                    else if (r == 'A' && Flag == true)
                    {
                        MessageBox.Show("Ansistors ante naku kuda thelyadu, niku theliste nee peru. mood petu ko pulka", "Result", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        this.BackColor = Color.LawnGreen;
                    }
                    else if (r == 'M' && Flag == true)
                    {
                        MessageBox.Show("Marriage Dawatch ee roju Mummy nee annam cheyadu ani chepu", "Result", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        this.BackColor = Color.LightSalmon;
                    }
                    else if (r == 'E' && Flag == true)
                    {
                        MessageBox.Show("Enemies anta I know that feel Bro....Fikar math kar idi just Game, Chill", "Result", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else if (r == 'S' && Flag == true)
                    {
                        MessageBox.Show("Sisters anta :-( ....Fikar math kar idi just Game.", "Result", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                }
            else if (Flag == false)
            {
                var Fname = FirstName.Text.ToLower();
                var Sname = SecondName.Text.ToLower();
                Fname = Fname.Trim();
                Sname = Sname.Trim();
                String[] name1_split = Fname.Split(new Char[] { ' ' });
                String[] name2_split = Sname.Split(new Char[] { ' ' });
                if (Fname == "" || Sname == "")
                {
                    MessageBox.Show("Enter a valid name Pulka ga");
                }
                else if (Fname == Sname)
                {
                    MessageBox.Show("Relation Should Exist between two persons, Not between You and You stupid I know you love your self");
                }
                else
                {

                    if (r == 'F')
                    {
                        MessageBox.Show("Friends, Jagratha ra ", "Result", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        this.BackColor = Color.Aqua;
                    }
                    else if (r == 'L')
                    {
                        MessageBox.Show("Lovers Pandaga Chesuko, naku kuda chudu mama", "Result", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        this.BackColor = Color.HotPink;
                    }
                    else if (r == 'A')
                    {
                        MessageBox.Show("Ansistors ante naku kuda thelyadu, niku theliste nee peru. mood petu ko pulka", "Result", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        this.BackColor = Color.LawnGreen;
                    }
                    else if (r == 'M')
                    {
                        MessageBox.Show("Marriage Dawatch ee roju Mummy nee annam cheyadu ani chepu", "Result", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        this.BackColor = Color.LightSalmon;
                    }
                    else if (r == 'E')
                    {
                        MessageBox.Show("Enemies anta I know that feel Bro....Fikar math kar idi just Game, Chill", "Result", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else if (r == 'S')
                    {
                        MessageBox.Show("Sisters anta :-( ....Fikar math kar idi just Game.", "Result", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
            }

        }
        private void Cancel_Click(object sender, EventArgs e)
        {
            System.Windows.Forms.Application.Exit();
        }

        private void selectedResultOutputToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Flag = false;
            r = 'F';
        }

        private void selectedResultOutputToolStripMenuItem_DoubleClick(object sender, EventArgs e)
        {
            Flag = true;
        }

        private void resetToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Flag = true;
        }

        private void resetingToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Flag = true;
            r = 'R';
        }

        private void loversToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Flag = false;
            r = 'L';
        }

        private void ansistorsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Flag = false;
            r = 'A';
        }

        private void marriageToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Flag = false;
            r = 'M';
        }

        private void enemiesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Flag = false;
            r = 'E';
        }

        private void sistersToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Flag = false;
            r = 'S';
        }

        private void button1_Click(object sender, EventArgs e)
        {
            AboutBox1 Ab = new AboutBox1();
            Ab.Show();
        }

        private void helpToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Help F3 = new Help();
            F3.Show();
        }
    }
}